var e = require("../@babel/runtime/helpers/defineProperty"),
  t = require("../@babel/runtime/helpers/createForOfIteratorHelper"),
  a = r(require("./showdown.js")),
  i = r(require("./html2json.js"));
function r(e) {
  return e && e.__esModule ? e : { default: e };
}
var n = 0,
  o = 0;
function d(e) {
  var t = e.target.dataset.src,
    a = e.target.dataset.from;
  void 0 !== a &&
    a.length > 0 &&
    wx.previewImage({ current: t, urls: this.data[a].imageUrls, showmenu: !1 });
}
function s(a) {
  var i = a.target.dataset.from,
    r = a.target.dataset.idx;
  void 0 !== i &&
    i.length > 0 &&
    (function (a, i, r, d) {
      var s = r.data[d];
      if (!s || 0 == s.images.length) return;
      var l,
        g = s.images,
        h = (function (e, t, a, i) {
          var r,
            d = 0,
            s = 0,
            l = {},
            g = a.data[i].view.imagePadding;
          o,
            e > (r = n - 2 * g)
              ? ((s = ((d = r) * t) / e),
                (l.imageWidth = d),
                (l.imageheight = s))
              : ((l.imageWidth = e), (l.imageheight = t));
          return l;
        })(a.detail.width, a.detail.height, r, d),
        m = g[i].index,
        v = "".concat(d),
        u = t(m.split("."));
      try {
        for (u.s(); !(l = u.n()).done; ) {
          var f = l.value;
          v += ".nodes[".concat(f, "]");
        }
      } catch (e) {
        u.e(e);
      } finally {
        u.f();
      }
      var c = v + ".width",
        w = v + ".height";
      r.setData(e(e({}, c, h.imageWidth), w, h.imageheight));
    })(a, r, this, i);
}
wx.getSystemInfo({
  success: function (e) {
    (n = e.windowWidth), (o = e.windowHeight);
  },
}),
  (module.exports = {
    wxParse: function () {
      var e =
          arguments.length > 0 && void 0 !== arguments[0]
            ? arguments[0]
            : "wxParseData",
        t =
          arguments.length > 1 && void 0 !== arguments[1]
            ? arguments[1]
            : "html",
        r =
          arguments.length > 2 && void 0 !== arguments[2]
            ? arguments[2]
            : '<div class="color:red;">数据不能为空</div>',
        n = arguments.length > 3 ? arguments[3] : void 0,
        o = arguments.length > 4 ? arguments[4] : void 0,
        l = n,
        g = {};
      if ("html" == t)
        (g = i.default.html2json(r, e)),
          console.log(JSON.stringify(g, " ", " "));
      else if ("md" == t || "markdown" == t) {
        var h = new a.default.Converter(),
          m = h.makeHtml(r);
        (g = i.default.html2json(m, e)),
          console.log(JSON.stringify(g, " ", " "));
      }
      (g.view = {}),
        (g.view.imagePadding = 0),
        void 0 !== o && (g.view.imagePadding = o);
      var v = {};
      (v[e] = g), l.setData(v), (l.wxParseImgLoad = s), (l.wxParseImgTap = d);
    },
    wxParseTemArray: function (e, t, a, i) {
      for (var r = [], n = i.data, o = null, d = 0; d < a; d++) {
        var s = n[t + d].nodes;
        r.push(s);
      }
      (e = e || "wxParseTemArray"),
        ((o = JSON.parse('{"' + e + '":""}'))[e] = r),
        i.setData(o);
    },
    emojisInit: function () {
      var e =
          arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : "",
        t =
          arguments.length > 1 && void 0 !== arguments[1]
            ? arguments[1]
            : "/wxParse/emojis/",
        a = arguments.length > 2 ? arguments[2] : void 0;
      i.default.emojisInit(e, t, a);
    },
  });
